package com.zzty.taskapp.common;

import java.io.File;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.Hashtable;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;

public class QRCode {

	public static void main(String[] args) throws Exception {
		System.out.println("begin");
		 String text = "http://www.baidu.com";   
	        int width = 300;   
	        int height = 300;   
	        String format = "png";   
	        Hashtable hints= new Hashtable();   
	        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");   
	         BitMatrix bitMatrix = new MultiFormatWriter().encode(text, BarcodeFormat.QR_CODE, width, height,hints);   
	         File outputFile = new File("new.png");   
	         //MatrixToImageWriter.writeToFile(bitMatrix, format, outputFile);
	         Path path = FileSystems.getDefault().getPath("C://Temp", "new.png");
	         
	 		MatrixToImageWriter.writeToPath(bitMatrix, format, path);
	 		
	 		System.out.println("end");
	}

}
